﻿Shader "Custom/NormalMappingCustomDiffuse" 
{
	Properties
	{
		_MainTex("Main(RGB)", 2D) = "white"{}

		_BumpTex("Bump", 2D) = "bump"{}
	}	

	SubShader
	{
		Tags
		{
			"RenderType" = "Opaque"
		}
		LOD 200

		CGPROGRAM
		#pragma surface surf CustomDiffuse

		sampler2D _MainTex;
		sampler2D _BumpTex;

		struct Input
		{
			float2 uv_MainTex;
			float2 uv_BumpTex;
		};

		void surf( Input IN, inout SurfaceOutput o)
		{
			half4 c = tex2D(_MainTex, IN.uv_MainTex);
			o.Normal = UnpackNormal(tex2D(_BumpTex, IN.uv_BumpTex));
			o.Albedo = c.rgb;
			o.Alpha = c.a;
		}

		inline float4 LightingCustomDiffuse(SurfaceOutput s, fixed3 lightDir, fixed atten)
		{
			float cosDiffuse = max(0, dot(s.Normal, lightDir));
			//cosDiffuse = cosDiffuse * 0.5 + 0.5;
			float4 color;
			color.a = s.Alpha;
			color.rgb = s.Albedo * _LightColor0.rgb * (cosDiffuse * atten * 2);

			return color;
		}

		ENDCG
	}

	FallBack "Diffuse"
}
